
let mixins={
     created() {
         this.rootData=_json

         console.log(this.rootData)

         if (this.rootData.type==1) {
            this.initDrawData()            
         }
     },
     mounted() {
        if (this.rootData.type==2) {
            setTimeout(()=>{
               this.initEducationTable()
               this.initgossipdata()
               this.initLineChart()
               this.initDraw()
            },500)
        }   
        if (this.rootData.type==3) {
            setTimeout(()=>{
            //    this.initEducationTable()
               this.initolddata()
               this.initLineoldChart()
               this.initDraw()
            },500)
        }       
     },
     data() {
        return {
           rootData:'',
           table1:{
                th:[],
                tr:[]
            },
            table2:{
                th:[],
                tr:[]
            },
            initMsg:[]
        }
     },
     methods: {
      initDrawData(){
         let _this=this
         _this.rootData.gapList.map((item,index)=>{
             let key=[..._this.rootData.gapList[index]['insuranceKey4']]
             let value=[]
             let title=_this.rootData.gapList[index]['memberKey']
             _this.rootData.gapList[index]['insuranceKey4'].forEach((ele,num) => {
                 value.push(_this.rootData.gapList[index]['insuranceKey3'][num])
             });

             //是否显示图表
             if (_this.rootData.isAllocation=='Y') {
                 //是否渲染图表
                 setTimeout(()=>{
                     _this.drawLine(`myChart${index+1}`,{
                             key,
                             value,
                             title
                     },)
                 },300)

             }
         })
     },
     drawLine(id,data){
     // 基于准备好的dom，初始化echarts实例
     let myChart = echarts.init(document.getElementById(id))
     // 绘制图表
     myChart.setOption({
             title:{
                 text: ``,
                 textStyle:{
                     fontSize:16,
                     fontFamily:'PingFang-SC-Medium',
                     fontWeight:'bolder',
                     color:'#333333'
                 },
                 left:10
             },
             xAxis: {
                 type: 'category',
                 data: data.key,
                 axisTick:{       //x轴刻度线
                     show:false
                 },
                 axisLabel:{
                     interval:0,
                     margin:10,
                     textStyle:{
                         color:"#222"
                     }
               },
             },
             yAxis: {
                 type: 'value',
                 axisLine:{
                     show:false
                 },
                 axisTick:{       //y轴刻度线
                     show:false
                 },
                 axisLabel:{
                     show:false
                 },
                 splitLine:{
                     show:false
                 },
 
             },
             series: [{
                 data: data.value,
                 type: 'bar',
                 barWidth:50,
                 label: {
                     normal: {
                         show: true,
                         position: 'top'
                     }
                 },
                 itemStyle: {
                     normal: {
                         // 随机显示
                         //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                       
                         // 定制显示（按顺序）
                         color: function(params) { 
                             var colorList = ['#2EC7C9','#B6A2DE','#5AB1EF','#FFB980']; 
                             return colorList[params.dataIndex] 
                         }
                     },
                 }
             }]
         });
     },

     initEducationTable(){
                let _this=this
                this.table1.th=['时间','年龄','阶段','学费','生活费','教育花费']
                this.table2.th=['时间','年龄','高等教育支出','折现至2034年']
                this.rootData.educationReoprt["discountingData"]&&this.rootData.educationReoprt.discountingData.discountingList.map((item,index)=>{
                    _this.table1.tr.push({
                        year:item.year+'年',
                        age:item.age+'岁',
                        educatinTarget:item.educatinTarget==0?'大学':'研究生',
                        tuition:item.tuition+'万元',
                        livingCosts:item.livingCosts+'万元',
                        expend:item.expend+'万元',
                    })
                    _this.table2.tr.push({
                        year:item.year+'年',
                        age:item.age+'岁',
                        expend:item.expend+'万元',
                        discounting:item.discounting+'万元'
                    })
                })

        },
        initgossipdata(){
            let radar=this.rootData.educationReoprt.radar.radarScore
            console.log(this.rootData.educationReport)
            let data={};
            data.indicator=[]
            data.value=[]
            for (let key in radar) {
                data.indicator.push({
                    name:key,
                    max:10
                })
                data.value.push(radar[key])
            }
            this.draw('mygossipChart',data)
        },
        initolddata(){
            let radar=this.rootData.retireReports.radar.radarScore
            console.log(this.rootData.educationReport)
            let data={};
            data.indicator=[]
            data.value=[]
            for (let key in radar) {
                data.indicator.push({
                    name:key,
                    max:10
                })
                data.value.push(radar[key])
            }
            this.draw('mygossipChart',data)
        },
       draw(id,data){
           let _this=this
            // 基于准备好的dom，初始化echarts实例
            let myChart = echarts.init(document.getElementById(id))
            // 绘制图表
            myChart.setOption({
                backgroundColor:'white',
                legend: {
                    data: ['评估结果'],
                    itemWidth:180,
                    itemHeight:10,
                    right:'5%',
                    top:'40%',
                    textStyle: {
                        fontSize:50
                    }
                },
                tooltip:{
                    backgroundColor: 'rgba(249, 249, 249, 0.85098)',
                    borderColor: 'rgb(124, 181, 236)',
                    borderWidth: 1,
                    textStyle: {
                        color: '#000',
                        fontSize:30
                    }
                },
                animation:false,
                radar: {
                    // shape: 'circle',
                    indicator: data.indicator,
                    // center: ['30%','50%'],
                    radius: '50%',
                    name: {
                        textStyle: {
                            fontSize:18
                        }
                    }
                },
                series: [{
                    name: '',
                    type: 'radar',
                    data : [
                        {
                            value : data.value,
                        }
                    ],
                    symbolSize:0
                }],
                color:['#2ca6e0']
            });
        },
        initLineChart(){
            this.initMsg=this.rootData.educationReoprt.recommend
        },
        initLineoldChart(){
            this.initMsg=this.rootData.retireReports.recommend
        },
        initDraw(){
            let _this=this
            let data={
                title:[],
                key:[],
                value:{},
                series:[]
            }
            this.initMsg.map((item,index)=>{

            data.title.push(item.name)
            item.list.map((x,y)=>{
                if (!data.value[index]) {
                    data.value[index]=[]
                }
                if (index==0) {
                    data.key.push(x.year)
                }
                data.value[index].push(x.money)
            })
            
              data.series.push({
                    name:data.title[index],
                    type:'line',
                    stack: '总量',
                    data:data.value[index]
              })
            })
            console.log(data)
            _this.drawtwoline('myLine',data)
            
       },
       drawtwoline(id,data){
           let _this=this
            // 基于准备好的dom，初始化echarts实例
            let myChart =echarts.init(document.getElementById(id))
            // 绘制图表
            myChart.setOption({
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data:data.title
                },
                    xAxis: {
                        type: 'category',
                        data: data.key
                    },
                    yAxis: {
                        type: 'value',
                         axisTick: {
                            show: false
                        },//隐藏刻度线
                        axisLine : {onZero: false,show:false},//隐藏y轴，
                        splitLine:{
                    　　　　show:true
                    　　 }
                        
                    },
                    series:data.series
                });
        },
     },
}




